import request from '@/utils/request'

export interface PermissionAssignUserRoleReqVO {
  userId: number
  roleIds: number[]
}

export interface PermissionAssignRoleMenuReqVO {
  roleId: number
  menuIds: number[]
}

export interface PermissionAssignRoleDataScopeReqVO {
  roleId: number
  dataScope: number
  dataScopeDeptIds: number[]
}

// 查询角色拥有的菜单权限
export const getRoleMenuList = async (roleId: number) => {
  return request({
    url: `/system/permission/list-role-menus?roleId=${roleId}`,
    method: 'GET',
  })
}

// 赋予角色菜单权限
export const assignRoleMenu = async (data: PermissionAssignRoleMenuReqVO) => {
  return request({
    url: '/system/permission/assign-role-menu',
    method: 'POST',
    data,
  })
}

// 赋予角色数据权限
export const assignRoleDataScope = async (
  data: PermissionAssignRoleDataScopeReqVO
) => {
  return await request({
    url: '/system/permission/assign-role-data-scope',
    method: 'POST',
    data,
  })
}

// 查询用户拥有的角色数组
export const getUserRoleList = async (userId: number) => {
  return await request({
    url: `/system/permission/list-user-roles?userId=${userId}`,
    method: 'GET',
  })
}

// 赋予用户角色
export const assignUserRole = async (data: PermissionAssignUserRoleReqVO) => {
  return await request({
    url: '/system/permission/assign-user-role',
    method: 'POST',
    data,
  })
}

// 分配用户角色
export const getUserRoles = (data: PermissionAssignUserRoleReqVO) => {
  return request({
    url: '/system/permission/get-user-roles',
    method: 'POST',
    data,
  })
}
